package ozu.project.continent;

import ozu.project.OzuPlayer;
import ozu.project.regions.OzuRegion;
import java.awt.*;


public class OzuContinent{
    private String name;
    private int continentValue;
    private Color color;
    private OzuRegion[] regions;

    public OzuContinent(String name, int continentValue, Color color, OzuRegion[] regions) {
        this.name = name;
        this.continentValue = continentValue;
        this.color = color;
        this.regions = regions;
    }

    public String getName() {
        return name;
    }

    public int getContinentValue() {
        return continentValue;
    }

    public Color getColor() {
        return color;
    }

    public OzuPlayer getOwner() {
        OzuPlayer player = this.regions[0].getOwner();
        for (int i = 1; i < this.regions.length; i++) {
             if (!this.regions[i].getOwner().equals(player)) return null;
        }
        return player;
    }

    public void giveReserves(OzuPlayer player) {
        //Could be replaced with "equals()", but then there have to be a check for if this.getOwner() is null first,
        //making it less preferable.
        //noinspection ObjectEquality
        if (this.getOwner() == player){
            player.addReserve(this.continentValue);
        }
    }

    public boolean containsRegion(OzuRegion region) {
        for (OzuRegion continentRegion : this.regions) {
            if (region.equals(continentRegion)) {
                return true;
            }
        }
        return false;
    }
}